package com.linhngua.code.gwt.server;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Currency;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import org.br.plotter.functions.FunctionLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.linhngua.code.gwt.client.RemoteInvocation;
import com.linhngua.code.gwt.client.data.shop.Item;
import com.linhngua.code.gwt.shared.Entity;

public class RemoteInvocationServlet extends RemoteServiceServlet implements
		RemoteInvocation {

	private static final Logger LOG = LoggerFactory
			.getLogger(RemoteInvocationServlet.class);

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Entity getEntity() {

		return new Entity("Linh");
	}

	@Override
	public Item getItem(int id) {
		return null;
	}

	@Override
	public Collection<String> listCurrencies() {
		Set<String> currencyList = new HashSet<String>();
		for (Locale locale : Locale.getAvailableLocales()) {
			// best effort
			try {
				currencyList
						.add(Currency.getInstance(locale).getCurrencyCode());
			} catch (Exception ex) {
				LOG.warn(ex.getMessage());
			}
		}
		List<String> list = new ArrayList<String>(currencyList);
		Collections.sort(list);
		return list;
	}

	@Override
	public Collection<String> listFunction() {
		List<String> list = new ArrayList<String>();
		for(String key:FunctionLocator.executer.keySet()){
			list.add(key);
		}

		Collections.sort(list);
		return list;
	}

}
